import Vue from 'vue'
import App from './App.vue'

import VueRouter from 'vue-router'
Vue.use(VueRouter)

import VueResource from 'vue-resource'
Vue.use(VueResource)

//1. 创建组件
import Home from './components/Home.vue';
import News from './components/News.vue';
import User from './components/User.vue';

//2. 配置路由
const routes = [
  { path: '/home', component: Home },
  { path: '/news', component: News, name:'newsName' },/*命名路由*/
  { path: '/user', component: User },
  { path: '*', redirect: '/home'}  /*默认跳转路由 */
]
//3. 实例化VueRouter
const router = new VueRouter({
  mode:'history',  /*编程式路由默认的hash模式改为history模式. hash模式在路径中带#号,history模式不带#,但是需在web服务器里配置*/
  routes // (缩写) 相当于 routes: routes
})

new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
